package com.skytech.tax.customsdatawarehouse.singlewindow.taxhandle.domain.dao;

import com.skytech.tax.customsdatawarehouse.singlewindow.taxhandle.domain.entity.GuaranteeLetterAmount;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class GuaranteeLetterAmountDao {

    @Resource
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    private final String insertGuaranteeLetterAmountSql = "INSERT INTO sw_guarantee_letter_amount (swAmountId, bkLetterCode, cusLetterCode, data, limitChangeTimeStr, socialCreditCode, storageTime)" +
            " VALUES (:swAmountId, :bkLetterCode, :cusLetterCode, :data, :limitChangeTimeStr, :socialCreditCode, :storageTime)";

    public void save(List<GuaranteeLetterAmount> list) {
        SqlParameterSource[] batch = SqlParameterSourceUtils.createBatch(list);
        namedParameterJdbcTemplate.batchUpdate(insertGuaranteeLetterAmountSql, batch);
    }


    private final String deleteGuaranteeLetterAmountSql = "DELETE FROM sw_guarantee_letter_amount WHERE swAmountId IN (:swAmountIds)";

    public void deleteBy(List<String> swAmountIds) {
        Map<String, Object> params = new HashMap<>();
        params.put("swAmountIds", swAmountIds);
        namedParameterJdbcTemplate.update(this.deleteGuaranteeLetterAmountSql, params);
    }
}
